﻿using System;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using log4net;
namespace AnyOffice.general.file_folder
{
    public partial class search : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.parentPath.DataSource = new LiteUtility().GetDtbDirectory();
                this.parentPath.DataTextField = "path";
                this.parentPath.DataValueField = "path";
                this.parentPath.DataBind();
                this.btnSubmit.Attributes.Add("onclick", "return CheckForm();");
            }
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("index.aspx");
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            this.pnlMain.Visible = false;
            string str = this.txtKey.Text.Replace("..", "");
            if (str.IndexOf("*") == -1)
            {
                str = "*" + str + "*";
            }
            foreach (char ch in "\\/:\"<>|")
            {
                str = str.Replace(ch.ToString(), "");
            }
            DataTable dtbSearch = new LiteUtility().GetDtbSearch(this.parentPath.Value, str);
            if (dtbSearch.Rows.Count == 0)
            {
                this.litMessage.Text = base.ShowPrompt("没有匹配的文件显示！");
            }
            else
            {
                this.pnlSearch.Visible = true;
                this.rptSearch.DataSource = dtbSearch;
                this.rptSearch.DataBind();
            }
        }

        public string formatSize(long size)
        {
            if ((size > 0L) && (size < 1024L))
            {
                return "1k";
            }
            if (size < 1048576L)
            {
                return (Convert.ToString((long)(size / 1024L)) + "k");
            }
            float num = Convert.ToSingle(size) / 1048576f;
            return (num.ToString("0.0") + "M");
        }   
   
        public string OfficeMenu(string path)
        {
            string str = string.Empty;
            if (((!path.ToLower().EndsWith("doc") && !path.ToLower().EndsWith("xls")) && (!path.ToLower().EndsWith("ppt") && !path.ToLower().EndsWith("docx"))) && (!path.ToLower().EndsWith("xlsx") && !path.ToLower().EndsWith("pptx")))
            {
                return str;
            }
            return (("<input type=\"button\" value=\"阅读\" class=\"SmallButton\" onClick=\"window.open('read.aspx?filename=" + Server.UrlEncode(path) + "',null,'menubar=0,toolbar=0,status=1,scrollbars=1,resizable=1');\"> ") + "<input type=\"button\" value=\"编辑\" class=\"SmallButton\" onClick=\"window.open('edit.aspx?filename=" + Server.UrlEncode(path) + "',null,'menubar=0,toolbar=0,status=1,scrollbars=1,resizable=1');\">");
        }


        public string Thumb(string path, string upDownMaximum)
        {
            string str = string.Empty;
            if ((!path.ToLower().EndsWith("gif") && !path.ToLower().EndsWith("jpg")) && ((!path.ToLower().EndsWith("jpeg") && !path.ToLower().EndsWith("bmp")) && !path.ToLower().EndsWith("png")))
            {
                return str;
            }
            str = "<a target=_blank href=show_photo.aspx?filename=" + Server.UrlEncode(path) + "><img align=absMiddle border=0 src=thumb.aspx?filename=" + Server.UrlEncode(path);
            if (upDownMaximum != string.Empty)
            {
                str = str + "&upDownMaximum=" + upDownMaximum;
            }
            return (str + "></a>");
        }
    }
}
